package cn.tedu.hospital.admin.server.statistics.service.impl;

import cn.tedu.hospital.admin.server.common.pojo.vo.PageData;
import cn.tedu.hospital.admin.server.statistics.dao.persist.repository.IStatisticsRepository;
import cn.tedu.hospital.admin.server.statistics.pojo.param.BadUseRatioParam;
import cn.tedu.hospital.admin.server.statistics.pojo.vo.PatientStatisticsVO;
import cn.tedu.hospital.admin.server.statistics.service.IStatisticsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 处理统计查询的业务实现类
 *
 * @author java@tedu.cn
 * @version 1.0
 */
@Slf4j
@Service
public class StatisticsServiceImpl implements IStatisticsService {

    @Value("${tea-store.dao.default-query-page-size}")
    private Integer defaultQueryPageSize;
    @Autowired
    private IStatisticsRepository statisticsRepository;

    @Override
    public PageData<PatientStatisticsVO> listByParam(Integer page, String division, String doctorName) {
        log.debug("开始处理【查询病人信息】的业务，页码：{}, 参数, 科别:{}, 医师:{}", page, division, doctorName);

        // TODO 还需判断如果查询不出数据,则返回异常信息

        Integer pageNum = page == null ? 1 : page;
        BadUseRatioParam badUseRatioParam = new BadUseRatioParam();
        badUseRatioParam.setDivision(division);
        badUseRatioParam.setDoctorName(doctorName);
        PageData<PatientStatisticsVO> pageData = statisticsRepository.listByParam(pageNum, defaultQueryPageSize, badUseRatioParam);
        return pageData;
    }

    @Override
    public PageData<PatientStatisticsVO> list(Integer page) {
        log.debug("开始处理【查询所有病人信息】的业务，页码：{}", page);
        Integer pageNum = page == null ? 1 : page;
        PageData<PatientStatisticsVO> pageData = statisticsRepository.list(pageNum, defaultQueryPageSize);
        return pageData;
    }

    @Override
    public PageData<PatientStatisticsVO> list(Integer page, Integer pageSize) {
        log.debug("开始处理【查询所有病人信息】的业务，页码：{}，每页记录数：{}", page, pageSize);
        Integer pageNum = page == null ? 1 : page;
        PageData<PatientStatisticsVO> pageData = statisticsRepository.list(pageNum, pageSize);
        return pageData;
    }
}
